// 结构体的深拷贝
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// 结构体声明
typedef struct student
{
    int id;
    char *name;
    int age;
}STU;

int main(int argc, char **argv)
{
    STU s1;
    STU s2;

    // 申请空间
    s1.name = calloc(50, sizeof(char));
    if (NULL == s1.name)
    {
        perror("calloc");
        return 1;
    }

    // 赋值
    strcpy(s1.name, "hello world");

    s2 = s1;

    // 进行深拷贝
    s2.name = calloc(50, sizeof(char));
    strcpy(s2.name, s1.name);

    // 输出验证
    printf("%s\n", s1.name);
    printf("%s\n", s2.name);

    // 释放
    free(s1.name);
    s1.name = NULL;
    free(s2.name);
    s2.name = NULL;
    return 0;
}